﻿using EMRView;
using EMRView.Extensions.HCAttribute;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EMRView.Extensions.Command.StandardCommand.File
{
    [Command(CommandType.文件, "OpenFile", "保存文件夹仅用于保存到文件时候使用")]
    public class OpenFileCommand : BaseCommand
    {
        public override Icon CommandIcon
        {
            get
            {
                return Properties.HCResource.打开;
            }
        }
        public override object Execute(HCEmrView _view, bool showDefaultUI = false, params object[] para)
        {
            OpenFileDialog vOpenDlg = new OpenFileDialog();
            try
            {
                vOpenDlg.Filter = "文件|*" + HC.View.HC.HC_EXT;
                if (vOpenDlg.ShowDialog() == DialogResult.OK)
                {
                    if (vOpenDlg.FileName != "")
                    {
                        Application.DoEvents();
                        _view.LoadFromFile(vOpenDlg.FileName);
                        _view.IsChanged = false;
                    }
                }
            }
            finally
            {
                vOpenDlg.Dispose();
                GC.Collect();
            }
            return null;
        }

        public override void InitControl(object control)
        {
        }
    }
}
